home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #1 / Amiga Plus CD - 1997 - No. 01.iso / pd / programmierung / tds / convsrc / tmodula2msg.mod < prev    next >
Text File  |  1995-11-01  |  4KB  |  119 lines

  1. (*
  2.  * TModula2Msg
  3.  * Error converter TurboModula/TDS - ©1994 by Matthias Bock (public domain)
  4.  * Bugs? Suggestions? Write to starfox@incubus.sub.org
  5.  *)
  6.  
  7. MODULE TModula2Msg;
  8.  
  9. FROM M2Lib IMPORT argc,argv;
  10. FROM Dos{37} IMPORT Lock,UnLock,FileLockPtr,ACCESS_READ,System,DeleteFile;
  11. FROM FIO IMPORT OpenToRead,File,Close,Status,IOStatus,EOF,ReadLn;
  12. FROM BIO IMPORT PutString,PutLine,PutInteger;
  13. FROM StdLib IMPORT atoi;
  14. FROM String IMPORT strcat,strcpy,strlen;
  15.  
  16. (*FROM Intuition IMPORT DisplayBeep;*)
  17.  
  18. CONST
  19.   maxStringLen=256;
  20.  
  21. VAR
  22.   flPtr:FileLockPtr;
  23.   s:ARRAY BOOLEAN OF ARRAY [0..maxStringLen] OF CHAR;
  24.   temp,name:ARRAY [0..80] OF CHAR;
  25.   inFile:File;
  26.   examine,delMode,switch:BOOLEAN;
  27.   line,numberStartPos,found,count,pos:INTEGER;
  28.   c:CHAR;
  29.  
  30. BEGIN
  31.   IF argc<>2 THEN HALT END;
  32.   switch:=FALSE;
  33.  
  34.   strcpy(name,argv^[1]);
  35.   strcpy(temp,argv^[1]);
  36.  
  37.   (* create error file name *)
  38.   pos:=strlen(temp);
  39.   IF (temp[pos-4]=".")
  40.   &((CAP(temp[pos-3])="D")&(CAP(temp[pos-2])="E")&(CAP(temp[pos-1])="F")
  41.   OR(CAP(temp[pos-3])="M")&(CAP(temp[pos-2])="O")&(CAP(temp[pos-1])="D"))
  42.   THEN
  43.     temp[pos-3]:="e";
  44.     temp[pos-2]:="r";
  45.     temp[pos-1]:="r";
  46.   END;
  47.   
  48.   (* is there an errorfile? *)
  49.   flPtr:=NIL;
  50.   flPtr:=Lock(temp,ACCESS_READ);
  51.   examine:=flPtr<>NIL;
  52.   UnLock(flPtr);
  53.   
  54.   IF examine THEN
  55.     (* Call M2E *)
  56.     s[switch]:="M2E ";
  57.     strcat(s[switch],name);
  58.     strcat(s[switch]," >T:TModula2Msg.tmp");
  59.     System(s[switch],NIL);
  60.  
  61.     (* Convert the errors *)
  62.     inFile:=OpenToRead("T:TModula2Msg.tmp");
  63.     IF IOStatus(inFile)=NoError THEN
  64.       REPEAT
  65.         ReadLn(inFile,s[switch]);
  66.         IF s[switch][0]="@" THEN
  67.           IF ~switch THEN   (* @--^---^ *)
  68.             pos:=0;
  69.           ELSE              (* @eyymxx: bla 'bla' *)
  70.             (* extract line number *)
  71.             count:=0; found:=0;
  72.             LOOP WHILE count<maxStringLen DO
  73.               CASE s[switch][count] OF
  74.                 |CHR(27): IF found=0 THEN found:=1 END;
  75.                 |"m": IF found=1 THEN found:=2 END;
  76.                 |"0".."9": IF found=2 THEN found:=3; numberStartPos:=count END;
  77.                 |":": IF found=3 THEN EXIT END;
  78.                 ELSE
  79.               END;
  80.             INC(count)END; HALT END;
  81.             FOR found:=0 TO count-numberStartPos DO
  82.               temp[found]:=s[switch][numberStartPos+found];
  83.             END;
  84.             temp[count-numberStartPos]:=0C;
  85.             line:=atoi(temp);
  86.             
  87.             (* extract horizontal position *)
  88.             WHILE (pos<maxStringLen)&(s[~switch][pos]<>"^") DO INC(pos) END;
  89.             INC(pos);
  90.             
  91.             (* extract error text *)
  92.             IF s[switch][count]=":" THEN INC(count) END;
  93.             IF s[switch][count]=" " THEN INC(count) END;
  94.             delMode:=FALSE;
  95.             found:=0;
  96.             WHILE (count<maxStringLen)&(s[switch][count]<>0C) DO
  97.               c:=s[switch][count];
  98.               IF c=CHR(27) THEN delMode:=TRUE END;
  99.               IF ~delMode THEN temp[found]:=c; INC(found) END;
  100.               IF c="m" THEN delMode:=FALSE END;
  101.             INC(count)END;
  102.             temp[found]:=0C;
  103.             
  104.             (* write message *)
  105.             PutString("<"); PutString(name); PutString("> ");
  106.             PutInteger(line); PutString(" "); PutInteger(pos); 
  107.             PutString(" E <"); PutString(temp); PutString(">"); PutLine;
  108.           END;
  109.           switch:=TRUE;
  110.         ELSE
  111.           switch:=FALSE;
  112.         END;
  113.       UNTIL EOF(inFile);
  114.       Close(inFile);
  115.       DeleteFile("T:TModula2Msg.tmp");
  116.     END;
  117.   END;
  118. END TModula2Msg.
  119.